//
//  GRXShopCarView.m
//  1-MushroomStreet-自定义tabbar
//
//  Created by xmg on 16/1/3.
//  Copyright © 2016年 grx. All rights reserved.
//

#import "GRXShopCarView.h"

@interface GRXShopCarView ()<UICollectionViewDataSource,UICollectionViewDelegate>


/**购物车篮*/
@property (nonatomic, weak) UICollectionView  *collectionView;


@end


@implementation GRXShopCarView

- (void)awakeFromNib{
        
    //添加子控件
    [self addChildView];
}

+ (instancetype)shopCarView{
    return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] firstObject];
}


    static NSString *const ID = @"cell";
//添加子控件
- (void)addChildView{

    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(self.width / 2.0, 200);
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.minimumLineSpacing = 10;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH) collectionViewLayout:flowLayout];
    
    collectionView.contentInset = UIEdgeInsetsMake(0, 0, 60, 0);
    
    collectionView.backgroundColor = [UIColor redColor];
    collectionView.delegate = self;
    collectionView.dataSource = self;
    [self insertSubview:collectionView atIndex:0];
    
    [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:ID];
    
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 2;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }
    
    return 50;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor whiteColor];
    
    return cell;
    
}


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        
        if (indexPath.item == 0) {
            
            return CGSizeMake(kScreenW, 200);
        }
    }
    
    
    return CGSizeMake((kScreenW - 30) / 2.0, 200);
}

//定义每个UICollectionViewcell 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    if (section == 0) {
        return UIEdgeInsetsMake(0, 0, 0, 0);
    }
    return UIEdgeInsetsMake(10, 10, 0, 10);
}



@end
